﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Collections;
using RAP.Framework.Libary.Utils;

namespace RAP.Framework.Libary.ServerCacheManager
{
  /// <summary>
  /// 缓存键值对象
  /// </summary>
  public class CacheKey
  {
    /// <summary>
    /// 将指定的完全键转换层CacheKey对象
    /// </summary>
    /// <param name="fullKey"></param>
    /// <returns></returns>
    public static CacheKey Create(string fullKey)
    {
      if (fullKey.IsNullOrEmpty())
      {
        return null;
      }
      return new CacheKey(fullKey.Split('.'));
    }

    public static CacheKey Create(params string[] keys)
    {
      return new CacheKey(keys);
    }

    public CacheKey() { }

    public CacheKey(params string[] keyArr)
    {
      IList keys = new List<string>(keyArr);
      if (keys.Count > 0)
      {
        this.ProxyKey = keys.Shift<string>();
      }
      if (keys.Count > 0)
      {
        this.ObjectKey = keys.Shift<string>();
      }
      if (keys.Count > 0)
      {
        this.ValueKey = keys.Join(".");
      }
    }

    /// <summary>
    /// 缓存代理Key
    /// </summary>
    public string ProxyKey { get; set; }

    /// <summary>
    /// 缓存对象Key
    /// </summary>
    public string ObjectKey { get; set; }

    /// <summary>
    /// 缓存值Key
    /// </summary>
    public string ValueKey { get; set; }

    public override string ToString()
    {
      return string.Join(".", this.ProxyKey, this.ObjectKey, this.ValueKey);
    }
  }
}
